<?php
	require_once dirname(BASEPATH) . '/application/controllers/system/_init.php';
	
	abstract class abs_article extends _init
	{
		function abs_article(){
			parent::__construct();
			$this->set_header_main();
		}
		function index() {			
			$this->set_navigation(array('<i class="icon-home"></i>หน้าแรก' => base_url(),									
										'บทความ' => base_url() . 'article'));
			
			$page = $this->input->get('p');
			$display_length = 8;
			if (!empty($page)) {
				$start_index = ($page-1) * $display_length;
				if ($start_index < 0)
					$start_index = 0;
			} else	
				$start_index = 0;
												
			$this->load->model('local/data/article/mod_article');
			$this->load->model('local/data/etc/mod_banner');
			$this->load->library('define/general_define');
							
			$data_content_0['data'] = $this->mod_article->get_article_list($display_length, $start_index);;
			$data_content_0['page_count'] = $this->mod_article->get_count() / $display_length;
			
			$data_banner['data'] = $this->mod_banner->get_banner_homepage_zone();
			$data_content_1['data'] = $this->mod_article->get_feature_article($this->general_define->feature_article_length);
			
			$this->template->write('content_1', $this->load->view('article/frm_article', $data_content_0, true));
			$this->template->write('right_sidebar', $this->load->view('widget/main/frm_banner_vertical', $data_banner, true));
			$this->template->write('right_sidebar', $this->load->view('widget/main/frm_feature_article', $data_content_1, true));
			$this->template->render();
		}
		function view(){
			$article_code = $this->uri->segment(3);
			
			$this->load->model('local/data/article/mod_article');
			$this->load->model('local/data/etc/mod_banner');
								
			$data_content_0['item'] = $this->mod_article->get_single_article($article_code);
			
			$this->set_navigation(array('<i class="icon-home"></i> หน้าแรก' => base_url(),										
										$data_content_0['item']['ART_CAT_NAME'] => base_url() . 'article/category/' . $data_content_0['item']['ART_CAT_NAME'],
										$this->mod_article->get_article_title_by_code($article_code) => base_url() . 'article/view/' . $article_code));
						
			$data_content_0['article_by_tag'] = $this->mod_article->get_article_title_by_tag(explode(',', $data_content_0['item']['ART_TAG']), 3, true);			
			$data_content_1['data'] = $this->mod_banner->get_banner_article_view_zone();			
			$data_content_2['data'] = $this->mod_article->get_article_title_by_category($data_content_0['item']['ART_CAT_ID'], 5);
		
			$this->template->write('content_1', $this->load->view('article/frm_article_view', $data_content_0, true));
			$this->template->write('right_sidebar', $this->load->view('widget/main/frm_banner_vertical', $data_content_1, true));
			$this->template->write('right_sidebar', $this->load->view('widget/main/frm_article_by_category', $data_content_2, true));					
			$this->template->render();
		}
		function tag(){			
			$tag = $this->uri->segment(3);
			
			if (!empty($tag)){
				$this->set_navigation(array('<i class="icon-home"></i>หน้าแรก' => base_url(),										
											'ป้ายกำกับ' => base_url() . 'article/tag',
											$tag => base_url() . 'article/tag/' . $tag));
				
				$page = $this->input->get('p');
				$display_length = 8;
				if (!empty($page)) {
					$start_index = ($page-1) * $display_length;
					if ($start_index < 0)
						$start_index = 0;
				} else	
					$start_index = 0;
												
				$this->load->model('local/data/article/mod_article');				
				$data_content['data'] = $this->mod_article->get_article_by_tag($tag, $display_length, $start_index);;
				$data_content['page_count'] = $this->mod_article->get_article_count_by_tag($tag) / $display_length;
				$data_content['tag'] = $tag;		 
				
				$this->template->write('content_1', $this->load->view('article/frm_article_tag', $data_content, true));				
			} else {
				$this->set_navigation(array('<i class="icon-home"></i>หน้าแรก' => base_url(),										
											'ป้ายกำกับ' => base_url() . 'article/tag'));
				
				$this->load->model('local/data/article/mod_tag');
				$data_content['data'] = $this->mod_tag->get_tag();
							
				$this->template->write('content_1', $this->load->view('article/frm_tag', $data_content, true));
			}
			
			$this->load->model('local/data/etc/mod_banner');
			$data_banner['data'] = $this->mod_banner->get_banner_homepage_zone();
			
			$this->template->write('right_sidebar', $this->load->view('widget/main/frm_banner_vertical', $data_banner, true));
			$this->template->render();
		}
		function category(){
			$category = $this->uri->segment(3);
			
			if (!empty($category)){		
				$this->set_navigation(array('<i class="icon-home"></i>หน้าแรก' => base_url(),	
											'หมวดหมู่' => base_url() . 'article/category',								
											urldecode($category) => base_url() . 'article/category/' . $category));
							
				$page = $this->input->get('p');
				$display_length = 8;
				if (!empty($page)) {
					$start_index = ($page-1) * $display_length;
					if ($start_index < 0)
						$start_index = 0;
				} else	
					$start_index = 0;
																
				$this->load->model('local/data/article/mod_article');							
				
				$data_content['data'] = $this->mod_article->get_article_by_category_name($category, $display_length, $start_index);
				$data_content['page_count'] = $this->mod_article->get_article_count_by_category_name($category) / $display_length;
				$data_content['category'] = $category;
				$this->template->write('content_1', $this->load->view('article/frm_article_category', $data_content, true));
			} else {
				$this->set_navigation(array('<i class="icon-home"></i>หน้าแรก' => base_url(),									
											'หมวดหมู่' => base_url() . 'article/category'));
											
				$this->load->model('local/data/article/mod_article_category');
				$data_content['data'] = $this->mod_article_category->get_category_list();
							
				$this->template->write('content_1', $this->load->view('article/frm_category', $data_content, true));
			}
			
			$this->load->model('local/data/etc/mod_banner');
			$data_banner['data'] = $this->mod_banner->get_banner_homepage_zone();
			
			$this->template->write('right_sidebar', $this->load->view('widget/main/frm_banner_vertical', $data_banner, true));
			$this->template->render();
		}	
	}
?>